package org.ouwa.lms.client.ui.event;

import org.ouwa.lms.client.support.event.ApplicationEvent;
import org.ouwa.lms.client.support.event.ApplicationEventSource;

/**
 * Triggered when a user successfully logged in the application.
 * 
 * @author lviet
 */
public class LoginEvent extends ApplicationEvent {
	private String username;
	private String loginUrl = "";
	private String nickname = "";
	
	private boolean credentialsOkay = false;
	
	public LoginEvent(ApplicationEventSource source) {
		super(source);
		username = "";
	}
	
	/**
     * Constructs a new LoginEvent.
     *
     * @param source The source of this event.
	 * @param username The username of the logged in user.
     */
	public LoginEvent(ApplicationEventSource source, String username) {
		super(source);
		this.username = username;
	}
	
	/**
     * Returns the username of the logged in user.
     *
     * @return The username of the logged in user.
     */
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public boolean isCredentialsOkay() {
		return credentialsOkay;
	}
	
	public void setCredentials(boolean credentialsOkay) {
		this.credentialsOkay = credentialsOkay;
	}
	
	public String getLoginUrl() {
		return loginUrl;
	}
	
	public void setLoginUrl(String loginUrl) {
		this.loginUrl = loginUrl;
	}
	
	public String getNickname() {
		return nickname;
	}
	
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	
	/**
     * {@inheritDoc}
     */
	public String getDescription() {
		if(credentialsOkay) {
			return "'" + username + "' has logged in.";
		}
		
		return "Authentication failed.";
	}
}
